package com.example.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Set;
import java.util.UUID;

/**
 * @Date 2022/8/14
 * @Author Jonathan
 */
@Slf4j
@Component
public class TestRedisBigKey {

    @Autowired
    private RedisTemplate redisTemplate;


    // @PostConstruct
    public void test1() {
        final Set keys = redisTemplate.keys("*");
        //log.info("keys:{}", keys);
        redisTemplate.opsForHash().put("m1", "1", "22");
        Object m1 = redisTemplate.opsForHash().get("m1", "1");
        log.info("删除之前m1:{}", m1);
        redisTemplate.delete("m1");
        m1 = redisTemplate.opsForHash().get("m1", "1");
        log.info("删除之后m1:{}", m1);
        for (int i = 0; i < 1000_0000; i++) {
            if (i % 10000 == 0) {
                log.info("i is:{}", i);
            }
            redisTemplate.opsForHash().put("myMap", String.valueOf(i), UUID.randomUUID());
        }
        log.info("开始删除key:{},数量是:{}", "myMap", redisTemplate.opsForHash().size("myMap"));
        final long t1 = System.currentTimeMillis();
        redisTemplate.delete("myMap");
        log.info("开始删除key:{}完成，花费时间:{}", "myMap", System.currentTimeMillis() - t1);

    }
}
